package br.com.ozsolucoes.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

@Entity
@NamedQueries({ @NamedQuery(name = "Categoria.consultarTodas", query = "select c from Categoria c"), 
	@NamedQuery(name = "Categoria.consultarPorId", query = "select c from Categoria c where c.id = :idCategoria"), 
	@NamedQuery(name = "Categoria.consultarCategoriasVingentes", query = "select c from ServicoCategoria sc, Categoria c where c.id = sc.categoria.id and sc.pk.idServico = :idServico"), 
	@NamedQuery(name = "Categoria.consultarServicoCategoriasVingentes", query = "select sc from ServicoCategoria sc where sc.pk.idServico = :idServico"), 
	@NamedQuery(name = "Categoria.consultarCategoriasVingentesString", query = "select c.categoria from ServicoCategoria sc, Categoria c where c.id = sc.categoria.id and sc.pk.idServico = :idServico"), 
	@NamedQuery(name = "Categoria.consultarPorCategoria", query = "select c from Categoria c where c.categoria = :categoria"), 
	@NamedQuery(name = "Categoria.consultarPorCategoriaAutoComplete", query = "select c.categoria from Categoria c where lower(c.categoria) like :categoria"),
	@NamedQuery(name = "Categoria.consultarCategoriasTicketCliente", query = "select distinct(t.categoria) from Ticket t where t.servico.cliente.id =:idCliente") 
})
public class Categoria implements Serializable {

	private static final long serialVersionUID = 63651191817731072L;

	@Id
	@GeneratedValue
	private long id;

	private String categoria;

	private double preco;
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Ticket.class, mappedBy = "categoria")
	private List<Ticket> tickets;

	@OneToMany(mappedBy = "categoria", cascade = CascadeType.REFRESH)
	private List<ServicoCategoria> servicoCategoria;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getCategoria() {
		return categoria;
	}

	public void setCategoria(String categoria) {
		this.categoria = categoria;
	}

	public double getPreco() {
		return preco;
	}

	public void setPreco(double preco) {
		this.preco = preco;
	}

	public List<Ticket> getTickets() {
		return tickets;
	}

	public void setTickets(List<Ticket> tickets) {
		this.tickets = tickets;
	}

	public List<ServicoCategoria> getServicoCategoria() {
		return servicoCategoria;
	}

	public void setServicoCategoria(List<ServicoCategoria> servicoCategoria) {
		this.servicoCategoria = servicoCategoria;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((categoria == null) ? 0 : categoria.hashCode());
		result = prime * result + (int) (id ^ (id >>> 32));
		long temp;
		temp = Double.doubleToLongBits(preco);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Categoria other = (Categoria) obj;
		if (categoria == null) {
			if (other.categoria != null)
				return false;
		} else if (!categoria.equals(other.categoria))
			return false;
		if (id != other.id)
			return false;
		if (Double.doubleToLongBits(preco) != Double.doubleToLongBits(other.preco))
			return false;
		return true;
	}

}